<template>
  <div v-loading="isloading2" class="jindu-container">
    <div class="header">
      <div><i class="el-icon-d-arrow-right"></i>编制村庄按条件筛选</div>
    </div>
    <table-header
      ref="header"
      @keychange="keychange"
      @cityChange="cityChange"
      @areaChange="areaChange"
    >
    </table-header>

    <div class="header">
      <div><i class="el-icon-d-arrow-right"></i>审核列表</div>
    </div>
    <div>
      <el-table
        :data="tableData"
        :span-method="objectSpanMethod"
        border
        row-key="id"
        style="width: 100%"
        class="eltable"
        :default-expand-all="isExpand"
        @expand-change="expand"
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
        v-loading="loading"
      >
        <el-table-column label="序号" width="100" prop="id">
          <template slot-scope="{ $index }">
            <span>{{ $index + 1 }}</span>
          </template>
        </el-table-column>

        <el-table-column prop="village" label="村庄名" width="150" />
        <el-table-column label="所属行政区划" width="240">
          　<template slot-scope="scope">
            <span>{{ scope.row.city }}</span
            >-<span>{{ scope.row.country }}</span
            >-<span>{{ scope.row.town }}</span>
          </template>
        </el-table-column>
        <el-table-column label="阶段完成进度[阶段当前年度截止日期]">
          <el-table-column
            v-for="item in rateArr"
            :key="item"
            prop=""
            :label="item"
            width="160"
          >
            <template slot-scope="scope">
              <div
                @click="openstate(scope.row.id, item.split('[')[0])"
                :class="[
                  scope.row.progressNames[item.split('[')[0]]
                    ? 'active'
                    : 'noclick',
                  'progressli',
                ]"
              >
                <el-progress
                  :percentage="scope.row.progressNames[item.split('[')[0]]"
                  :format="format"
                  text-inside
                  :color="customColorMethod"
                ></el-progress>
              </div>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column prop="completionYear" label="任务年限" width="200">
          <template slot-scope="scope">
            <div v-if="scope.row.completionYear">
              {{ scope.row.completionYear }}
            </div>
            <div v-else>暂无限制</div>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        v-if="tableData.length > 0"
        class="elpagi"
        :total="total"
        @size-change="getdata"
        @current-change="getdata"
        @prev-click="getdata"
        @next-click="getdata"
        :current-page.sync="listquery.currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size.sync="listquery.pageSize"
        layout="total,sizes, prev, pager, next, jumper"
      />
      <right-div
        :list="resultList"
        v-if="rightPanelShow"
        @closeRightPanel="closeRightPane"
        :fileList="fileList"
        :title="title"
      ></right-div>
    </div>
  </div>
</template>
<script>
import tableHeader from "../components/TableHeader";
import rightDiv from "../components/rightDiv";

import { progresslist } from "@/api/index.js";
import { picHost } from "@/settings.js";
import { getnowwarning } from "@/api/notice.js";
export default {
  components: {
    tableHeader,
    rightDiv,
  },
  data() {
    return {
      AAA: {},
      listquery: {
        pageSize: 10,
        currentPage: 1,
        city: null,
        country: null,
        key: "",
        isMerge: false,
      },
      isExpand: false,
      afterVillage: {
        city: "",
        country: "",
        town: "",
        village: "",
      },
      boxshow: false,
      rightNowVillage: "",
      isloading2: false,
      fileList: [],
      fileDataList: [],
      total: 0,
      isBlack: false,
      resultList: [],
      title: "",
      progress: 0,

      rightPanelShow: false,
      tipshow: false,
      rateArr: [],
      downloadurl: "",
      loading: false,
      tableData: [],
      dataform: {},
    };
  },
  watch: {
    fileList(n) {
      if (n.length <= 0) {
        this.tipshow = false;
      }
    },
  },
  methods: {
    expand(data, row) {
      data.state = row;

      this.AAA.set(data.id, row);
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex > 1) {
        if (row.children && row.state) {
          return {
            rowspan: row.children.length + 1,
            colspan: 1,
          };
        } else if (row.isChildren) {
          return {
            rowspan: 1,
            colspan: 0,
          };
        } else {
          return {
            rowspan: 1,
            colspan: 1,
          };
        }
      }
    },
    tijiao(row) {
      this.rightNowVillage = row;
      this.dialogVisible = true;
      this.progress = 0;
    },

    //进度条颜色
    customColorMethod(percentage) {
      if (percentage < 30) {
        return "#909399";
      } else if (percentage < 70) {
        return "#e6a23c";
      } else {
        return "#67c23a";
      }
    },

    format(percentage) {
      return `${percentage}%`;
    },

    query(scope) {
      this.$router.push({ path: "/stage/stageCount", query: scope.row });
    },

    openstate(id, name) {
      this.title = name;
      this.rightPanelShow = true;
      this.resultList = [];
      this.tableData.forEach((element) => {
        if (
          element.id == id &&
          element.progressList != "" &&
          element.progressList[name]
        ) {
          let objv = element.progressList[name].content;
          if (objv) {
            objv.forEach((v, i) => {
              let imgslist = objv[i].files;
              let treelist = [];
              let treelist1 = [];
              if (imgslist) {
                imgslist.forEach((element) => {
                  let label = element.substring(element.lastIndexOf("/") + 1);
                  let obj = {
                    label: label,
                    url: element,
                  };
                  treelist.push(obj);
                });
              }
              objv[i].Imglist = treelist;
              this.resultList.push(objv[i]);
            });
          }
        }
      });
    },
    closeRightPane() {
      this.rightPanelShow = false;
    },
    keychange(data) {
      this.listquery.key = data;
      this.listquery.currentPage = 1;
      this.getdata();
    },
    cityChange(data) {
      this.listquery.city = data;
      this.listquery.country = null;
      this.listquery.currentPage = 1;
      this.getdata();
    },
    areaChange(data) {
      this.listquery.city = data.city;
      this.listquery.country = data.country;
      this.listquery.currentPage = 1;
      this.getdata();
    },

    async getdata() {
      this.loading = true;
      let res = await progresslist(this.listquery);
      res.data.content.forEach((v) => {
        v.progressNames.forEach((p) => {
          v.progressNames[p.name] = p.count;
        });
      });

      this.tableData = res.data.content;
      this.total = res.data.totalElements;
      this.isBlack = res.isblack;
      this.tableData.forEach((element) => {
        if (element.children) {
          if (this.AAA.has(element.id)) {
            element.state = this.AAA.get(element.id);
          } else {
            element.state = this.isExpand;
          }
        }
      });
      this.AAA = new Map();
      this.loading = false;
    },
  },
  mounted() {
    this.AAA = new Map();
    this.getdata();

    getnowwarning()
      .then((res) => {
        let result = res.data;
        let ratelist = [];
        if (result.progressAt1) {
          ratelist.push(`准备工作[${result.progressAt1.split(" ")[0]}]`);
        } else {
          ratelist.push("准备工作[暂无限制]");
        }
        if (result.progressAt2) {
          ratelist.push(`基础调查[${result.progressAt2.split(" ")[0]}]`);
        } else {
          ratelist.push("基础调查[暂无限制]");
        }
        if (result.progressAt3) {
          ratelist.push(`编制方案[${result.progressAt3.split(" ")[0]}]`);
        } else {
          ratelist.push("编制方案[暂无限制]");
        }
        if (result.progressAt4) {
          ratelist.push(`咨询论证[${result.progressAt4.split(" ")[0]}]`);
        } else {
          ratelist.push("咨询论证[暂无限制]");
        }
        if (result.progressAt5) {
          ratelist.push(`审查审核[${result.progressAt5.split(" ")[0]}]`);
        } else {
          ratelist.push("审查审核[暂无限制]");
        }
        if (result.progressAt6) {
          ratelist.push(`审批公告[${result.progressAt6.split(" ")[0]}]`);
        } else {
          ratelist.push("审批公告[暂无限制]");
        }
        this.rateArr = ratelist;
      })
      .catch((err) => {
        let ratelist = [];
        ratelist.push("准备工作");
        ratelist.push("基础调查");
        ratelist.push("编制方案");
        ratelist.push("咨询论证");
        ratelist.push("审查审核");
        ratelist.push("审批公告");
        this.rateArr = ratelist;
      });
  },
};
</script>
<style lang="scss" scoped>
@import "../../../../public/css/table.scss";
.jindu-container {
  margin: 5px;
  padding-bottom: 10px;
  overflow-y: auto;
  position: relative;
  height: 100%;
}

::v-deep .el-badge__content.is-fixed {
  position: absolute;
  top: 5px;
  right: 50px;
  -webkit-transform: translateY(-50%) translateX(100%);
  transform: translateY(-50%) translateX(100%);
}
.downButton {
  display: flex;
  align-items: center;
  .header-button {
    padding: 5px;
    border-radius: 50%;
  }
  .header-tip {
    margin-right: 10px;
    display: flex;
    font-weight: 500;
    align-items: center;
    font-size: 14px;
    width: 400px;
    overflow: hidden;
    .gundong {
      padding-left: 0px;
      font-size: 12px;
      color: #000;
      display: inline-block;
      white-space: nowrap;
      animation: 10s wordsLoop linear infinite normal;
    }
    @keyframes wordsLoop {
      0% {
        transform: translateX(200px);
        -webkit-transform: translateX(200px);
      }
      100% {
        transform: translateX(-100%);
        -webkit-transform: translateX(-100%);
      }
    }

    @-webkit-keyframes wordsLoop {
      0% {
        transform: translateX(200px);
        -webkit-transform: translateX(200px);
      }
      100% {
        transform: translateX(-100%);
        -webkit-transform: translateX(-100%);
      }
    }
    i {
      font-size: 18px;
      color: #ee9a00;
    }
  }
}

::v-deep .el-progress-bar__outer {
  height: 15px !important;
}
::v-deep .el-table thead.is-group th {
  /* background: #f5f7fa; */
  background-color: #8e98b5;
}
.progressli {
  display: flex;
  justify-content: space-between;
  align-items: center;
  ::v-deep .el-progress {
    width: 130px;
  }
  .spanicon {
    width: 23px;
    height: 23px;
    font-size: 10px;
    border-radius: 50%;
    margin-left: 5px;
  }
}
.active {
  // background-color: #4778c7;
  color: #fff;
  cursor: pointer;
  // border: 1px solid #4778c7;
}
.noclick {
  pointer-events: none !important;
}
.jddengji {
  display: flex;
  justify-content: left;
  padding: 10px;
  align-items: center;
  .tips {
    margin-left: 15px;
    font-size: 14px;
    i {
      color: #cd5555;
      margin-right: 5px;
      font-size: 18px;
    }
  }
}
.demo1 {
  line-height: 52px;
  // display: flex;
  // align-items: center;
}

.warn {
  background-color: #cd5555;
}
.header {
  font-size: 14px;
  font-weight: 600;
  line-height: 35px;
  margin-right: 5px;
  border-bottom: 1px dashed #ccc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  i {
    color: #4778c7;
  }
}
.tip1 {
  margin-top: 0;
  line-height: 22px;
  margin-left: 10px;
}
.tip2 {
  color: red;
  line-height: 22px;
  margin-left: 10px;
}
::v-deep .el-dialog__body {
  padding: 0 20px 10px 20px;
}
// .downButton {
//   background-color: #4778c7;
//   color: #fff;
//   border-radius: 5px;
//   height: 32px;
//   line-height: 32px;
//   font-size: 14px;
//   padding: 0px 15px;
//   letter-spacing: 1px;
//   i {
//     margin-right: 5px;
//   }
// }
</style>
